package com.zzw.service;

import com.zzw.entity.OauthClientToken;

import com.zzw.util.MyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@CacheConfig(cacheNames = "oauthClientTokenService")
public class OauthClientTokenService{
    @Autowired
    protected MyMapper<OauthClientToken> mapper;

    @CachePut(key = "#p0.id", unless = "#result eq null")  //#p0表示第一个参数
    public OauthClientToken insert(OauthClientToken oauthClientToken) {
        mapper.insert(oauthClientToken);
        return oauthClientToken;
    }

    @CachePut(key = "#p0.id", unless = "#result eq null")  //#p0表示第一个参数
    public OauthClientToken update(OauthClientToken oauthClientToken) {
        mapper.updateByPrimaryKey(oauthClientToken);
        return oauthClientToken;
    }

    @CacheEvict(key = "#p0.id")  //删除缓存名称为userCache,key等于指定的id对应的缓存
    public int delete(OauthClientToken oauthClientToken) {
        return mapper.delete(oauthClientToken);
    }

    @Cacheable(key = "#p0.id", unless = "#result eq null")  //#p0表示第一个参数
    public OauthClientToken select(OauthClientToken oauthClientToken) {
        return mapper.selectOne(oauthClientToken);
    }

    @CacheEvict(allEntries=true)
    public int deleteAll() {
        return mapper.delete(null);
    }

    @CacheEvict(allEntries=true)
    public int deleteByIds(String ids) {
        return mapper.deleteByIds(ids);
    }
}
